from re import S
from Netlayer.DeviceListener import *
from Netlayer.DeviceHolder import *
from GUI.DeviceListGUI import *
from threading import Thread


def scanDeviceInNet(ip,mask,myDeviceListGui):
    myDeviceListener = DeviceListener(ip,mask)
    DeviceList = myDeviceListener.scan()
    print(DeviceList)
    for item in DeviceList:
        myDeviceListGui.deviceList.insert('end',str(item))


if __name__ == '__main__':
    ##建立所有对象
    
    myDeviceHolder = DeviceHolder("10.39.12.163")

    ##GUI必须放在主线程
    myDeviceListGui = DeviceListGui("800x600")

    ##入网挂机线程，用于让别人检测到
    DeviceHoldThread = Thread(target=myDeviceHolder.hold)
    DeviceHoldThread.start()

    ##扫描子网主机线程
    DeviceListenThread = Thread(target=lambda:scanDeviceInNet("10.39.12.163","255.255.0.0",myDeviceListGui))
    DeviceListenThread.start()

    myDeviceListGui.MainLoop()